class Point
    attr_accessor:x,:y
    def initialize(x=0,y=0)
        @x,@y=x,y
    end
    def inspect 
        "(#{x},#{y})"
    end
    def +(p)
        self.class.new(x+p.x,y+p.y)
    end
    def -(p)
        self.class.new(x-p.x,y-p.y)
    end
    def +@
        dup #自己的副本
    end
    def -@
        self.class.new(-x,-y)
    end
    def ~@
        self.class.new(-y,x)
    end
    def [](index)
        case index
        when 0
            x
        when 1
            y
        else
            raise ArgumentError,"out of range '#{index}'"
        end
    end
    def []=(index,val)
        case index
        when 0
            self.x=val
        when 1
            self.y=val
        else 
            raise ArgumentError,"out of range '#{index}'"
        end
    end
    def swap(p)
        tmp_x,tmp_y=@x,@y 
        @x,@y=p.x,p.y 
        p.x,p.y=tmp_x,tmp_y
        return self
    end
end
